const TestUtils = require('./testUtils');
const bcrypt = require('bcryptjs');

describe('TestUtils 工具类方法', () => {
  test('generateTestToken 应生成有效 token', () => {
    const token = TestUtils.generateTestToken(1, 'user');
    expect(typeof token).toBe('string');
  });

  test('getTestUser 应返回默认用户对象', () => {
    const user = TestUtils.getTestUser();
    expect(user.username).toBe('testuser');
  });

  test('getTestAdmin 应返回管理员对象', () => {
    const admin = TestUtils.getTestAdmin();
    expect(admin.role).toBe('admin');
  });

  test('getHashedPassword/verifyPassword 正确加密和校验', async () => {
    const password = 'abc123';
    const hash = await TestUtils.getHashedPassword(password);
    expect(await TestUtils.verifyPassword(password, hash)).toBe(true);
    expect(await TestUtils.verifyPassword('wrong', hash)).toBe(false);
  });

  test('getTestFund/getTestPortfolio/getTestStrategy 返回对象', () => {
    expect(TestUtils.getTestFund().name).toBe('测试基金');
    expect(TestUtils.getTestPortfolio().name).toBe('测试组合');
    expect(TestUtils.getTestStrategy().name).toBe('测试策略');
  });

  test('setupTestEnvironment/resetTestEnvironment 设置和重置环境变量', () => {
    TestUtils.setupTestEnvironment();
    expect(process.env.NODE_ENV).toBe('test');
    TestUtils.resetTestEnvironment();
    expect(process.env.NODE_ENV).toBeUndefined();
  });

  test('cleanupTestData 不抛异常', async () => {
    const fakeQuery = jest.fn();
    await expect(TestUtils.cleanupTestData(fakeQuery)).resolves.toBeUndefined();
  });
}); 